package com.buobao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buobao.entity.Evaluation;
import com.buobao.mapper.EvaluationMapper;
import com.buobao.service.EvaluationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

import static org.springframework.transaction.annotation.Propagation.NOT_SUPPORTED;

@Service("evaluationService")
@Transactional(propagation = NOT_SUPPORTED, readOnly = true)
public class EvaluationServiceImpl implements EvaluationService {
    @Resource
    private EvaluationMapper evaluationMapper;

    @Override
    public List<Evaluation> getEvaluationByBookId(Long bookId) {
//        QueryWrapper<Evaluation> evaluationQueryWrapper = new QueryWrapper<>();
//        evaluationQueryWrapper.eq("book_id",bookId);
//        evaluationQueryWrapper.eq("state","enable");
//        evaluationQueryWrapper.orderByDesc("create_time");
        return evaluationMapper.selectListWithName(bookId);
    }

    @Override
    public Evaluation getEvaluationById(Long evaluationId) {
        Evaluation evaluation = evaluationMapper.selectOne(new QueryWrapper<Evaluation>().eq("evaluation_id", evaluationId));
        return evaluation;
    }

    @Transactional
    @Override
    public Evaluation insertEvaluation(Evaluation evaluation) {
        evaluationMapper.insert(evaluation);
        return evaluation;
    }

    @Transactional
    @Override
    public Evaluation updateEvaluation(Evaluation evaluation) {
        evaluationMapper.update(evaluation,new QueryWrapper<Evaluation>().eq("evaluation_id",evaluation.getEvaluationId()));
        return evaluation;
    }
}






























